Part Number Hot Search : 
MD1802FH PSMN0 05000 LS21G 01M321VT TCC76 607039 MC431R
Product Description
Full Text Search
 

To Download AN792 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  rev. 0.3 5/14 copyright ? 2014 by silicon laboratories AN792 AN792 cp2130 i nterface s pecification 1. introduction the silicon labs cp2130 usb-to-spi bridge is a device that communicates over the universal serial bus (usb) using vendor-specific control and bulk transfers to perform serial peripheral interface (spi) data transfers. the cp2130 employs usb bulk-mode transfers for high sustai ned data throughput. the cp2130 also includes flexible gpio functions that can be configured and accessed vi a usb. this document is t he specification for the usb transfers supported by the cp2130 and describes the configurable parameters. silicon labs provides 32-bit an d 64-bit dynamic link libraries that adher e to this specification for the following operating systems: ? windows xp ? (sp2 & sp3), vista ? , 7 ? , and 8 ? this document is inte nded for the following: ? users on osx or linux who want to integrate the device using libusb. ? users who are using an operating system that is not supported by the dynamic link libraries and who need to implement their own interface. ? users who want to integrate the devi ce interface into their application. to use the cp2130 device: ? for windows ?? the recommended method of use with windows is through the dll, which is installed with the cp2130 software package for windows and can be found here: c:\silabs\mcu\cp2130_sdk\software\library ?? if you would like to interface with the device directly, you can use this document as a guide for the packet format the cp2130 expects. ? for linux ?? read section 8 of this document for detailed instruct ions on how to use this interface spec with libusb ? for osx ?? install libusb on osx using the instructions on the libusb website ?? read section 8.1.3, 8.1.4 and 8.1.5 for instructions on how to use this interface spec with libusb
AN792 2 rev. 0.3 figure 1. system architecture diagram pc user application (implements cp2130 interface specification) generic usb driver (provided by os / 3 rd party) usb host controller / root hub cp2130 usb-to-spi bridge spi slave device usb
AN792 rev. 0.3 3 1.1. additional documentation ? cp2130 data sheet: http://www.silabs.com/products/interface/usbtospi ? cp2130 usb-to-spi api specification for windows. the api doc umentation and libraries are included in the cp2130 software developm ent kit (sdk), which is available for download at: http://www.silabs.com/cp2130ek ? an721: cp21xx device customization guide: http://www.silabs.com/i nterface-appnotes ? usb 2.0 specification: http://www.usb.org /developers/docs/
AN792 4 rev. 0.3 2. usb endpoints the cp2130 uses three usb endpoints to communicate with the usb host: ? control endpoint 0?used for usb standard requests as well as vendor requests used to send and receive configuration and control commands to the device. ? bulk endpoint 1?used for spi data transfer commands ? bulk endpoint 2?used for spi data transfer commands table 1 describes the usb end point usage and capabilities. the cp2130 supports two types of commands: data tran sfer commands and configuration and control commands. data transfer commands are used to send and receive dat a over the spi. configuration and control commands are used to configure the spi parameters and config ure the cp2130 one-time programmable (otp) rom. 2.1. data transfer priority the cp2130 usb endpoint 1 uses a double-buffered fifo , whereas endpoint 2 uses a single-buffered fifo. to improve spi data transfer performance, endpoint 1 can be used to double-buffer read data or write data transfer packets. the transfer priority can be configured for high- priority write or high-pri ority read mode. the transfer direction with the higher priority w ill use the double-buffered endpoint and the transfer direction with the lower priority will use the single-buffered endpoint. see the set_usb_config (command id 0x61) command for more information on how to configure the data transfer priority. table 1. usb endpoint usage endpoint number endpoint type max packet size (bytes) direction (high-priority write)* direction (high-priority read)* 0 control 64 in / out 1 bulk 64 (double-buffered) out in 2 bulk 64 (single-buffered) in out *note: in refers to packets sent from device-to-host. out refers to packets se nt from host-to-device.
AN792 rev. 0.3 5 3. control transfers a usb control transfer consists of a setup stage, an opti onal data in or data out stage, and a status stage. control transfer requests are used to send configur ation and control commands to the cp2130 using vendor requests. for a set operation, the wlength field specifies the number of data byte s that will be sent out by the usb host as part of the command in the data phase. for a get operation, the wlength field specifies the number of bytes that will be returned in by the usb device. table 2 describes the contents of the setup packet sent fr om the host to the device during the setup stage. the setup packet can be used to initia te a configuration and control command. refer to the usb 2.0 specification for mo re information abou t control transfers. table 2. control transfer setup packet name offset size value description bmrequesttype 0 1 bitmap characteristics of request brequest 1 1 value specific request wvalue* 2 2 value 16-bit field varies according to request (little-endian) windex* 4 2 value 16-bit field varies according to request (little-endian) wlength 6 2 count number of bytes to transfer if there is a data stage (little-endian) *note: setup packet fields not specified in the command sections are not used and should be set to 0. table 3. bmrequesttype bitmap bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 direction type recipient bit name description 7 direction data transfer direction 0: host-to-device 1: device-to-host 6:5 type type 00: standard 01: class 10: vendor 11: reserved 4:0 recipient recipient 00000: device 00001: interface 00010: endpoint 00011: other 00100?11111: reserved
AN792 6 rev. 0.3 4. multi-byte field endianness multibyte fields can be sent over usb in big-endian or lit tle-endian byte order. fields marked as big-endian are sent most-significant byte first followed by less significant bytes. fields marked as little-endi an are sent least-significant byte first followed by more significan t bytes. figure 2 shows an example of big-endian byte order, and figure 3 shows an example of little-endian byte order. figure 2. big-endian byte order figure 3. little-endian byte order msb lsb ... most-significant byte (msb) first 0x12 0x34 example: byte order for an unsigned 16-bit value: 0x1234 big-endian 0x12 example: byte order for an unsigned 32-bit value: 0x12345678 0x34 0x56 0x78 lsb msb ... least-significant byte (lsb) first 0x34 0x12 example: byte order for an unsigned 16-bit value: 0x1234 little-endian 0x78 example: byte order for an unsigned 32-bit value: 0x12345678 0x56 0x34 0x12
AN792 rev. 0.3 7 5. data transfer commands (bulk transfers) data transfer commands from usb to spi are implemented using usb bulk-mode transfers on usb endpoints 1 and 2. the direction of endpoint 1 and endpoint 2 are dependent on the transfer priority setting. any previous data transfer command must complete before another data transfer command is issued. the host may issue control commands (on endpoint 0) wh ile data transfer commands are in progress. a summary of these commands is given in table 4 with detailed description s in following sections. table 4. data transfer commands command name command id comment page read 0x00 reads data from the spi miso line to usb 8 write 0x01 write data from usb to the spi mosi line. 9 writeread 0x02 simultaneous write/read from usb to mosi/miso 10 readwithrtr 0x04 read data when rtr (readytoread) pin is asserted 11
AN792 8 rev. 0.3 5.1. read (command id 0x00) 5.1.1. description read data bytes from spi miso line to usb. 5.1.2. command (out transfer) 5.1.3. response (in transfer) 5.1.4. remarks the cp2130 returns as many packets as needed for the full transfer. if the transfer lengt h is not a multiple of 64 bytes, then the last packet will be a s hort packet; otherwise the cp 2130 will send a zero-leng th packet to indicate that the in transfer has completed. the cp2130 drives the mosi line high during read transfers. name offset size value description reserved 0 2 0x0000 must be 0x0000 command id 2 1 0x00 command id reserved 3 1 0x00 must be 0x00 length 4 4 count specifies the number of bytes to read (little-endian) name offset size value description data 0 length array the spi read data from the miso line
AN792 rev. 0.3 9 5.2. write (command id 0x01) 5.2.1. description write data bytes from usb to spi mosi line. 5.2.2. command (out transfer) 5.2.3. remarks the bulk out transfer consists of u sb packets. the maximum usb packet size is 64 bytes. the first packet can contain up to 56 bytes of data and may be followed by pack ets of up to 64 bytes of data. the last packet may be a partial packet. the cp2130 disregards the state of th e miso line during a write transfer. name offset size value description reserved 0 2 0x0000 must be 0x0000 command id 2 1 0x01 command id reserved 3 1 0x00 must be 0x00 length 4 4 count specifies the number of bytes to write (little-endian) data 8 length array the spi data to write to the mosi line
AN792 10 rev. 0.3 5.3. writeread (command id 0x02) 5.3.1. description write data bytes to spi mosi and read data bytes from spi miso simultaneously. 5.3.2. command (out transfer) 5.3.3. response (in transfer) 5.3.4. remarks the cp2130 returns as many packets as needed for the full transfer. if the transfer lengt h is not a multiple of 64 bytes, then the last packet will be a s hort packet; otherwise the cp 2130 will send a zero-leng th packet to indicate that the in transfer has completed. the spi supports full-duplex communication and the spi write and spi read occur simultaneously. name offset size value description reserved 0 2 0x0000 must be 0x0000 command id 2 1 0x02 command id reserved 3 1 0x00 must be 0x00 length 4 4 count specifies the number of bytes to read (little-endian) data 8 length array the spi data to write to the mosi line name offset size value description data 0 length array the spi read data from the miso line
AN792 rev. 0.3 11 5.4. readwithrtr (command id 0x04) 5.4.1. description read data bytes from spi miso to usb as long as the rtr pin (gpio.3 / cs3 / rtr) is asserted. pause the read if rtr (ready-to-read) is not asserted. 5.4.2. command (out transfer) 5.4.3. response (in transfer) 5.4.4. remarks the cp2130 returns as many packets as needed for the full transfer. if the transfer lengt h is not a multiple of 64 bytes, then the last packet will be a s hort packet; otherwise the cp 2130 will send a zero-leng th packet to indicate that the in transfer has completed. the cp2130 drives the mosi line high during read transfers. the spi byte transfers will be paused if the rtr pin is not asserted. spi byte transfers will resume when rtr is asserted. name offset size value description reserved 0 2 0x0000 must be 0x0000 command id 2 1 0x04 command id reserved 3 1 0x00 must be 0x00 length 4 4 count specifies the number of bytes to read (little-endian) name offset size value description data 0 length array the spi read data from the miso line
AN792 12 rev. 0.3 6. configuration and control commands (control transfers) all cp2130 configuration and control commands are implem ented using vendor-specific control transfers on the usb control endpoint (endpoint 0). these commands consist of a command id, command-dependent arguments, and return data for get requests. a summary of these commands is given in table 5 with detailed description s in following sections. table 5. configuration and control commands command name command id comment page get_clock_divider 0x46 get the gpio.5 / cs5 / clkout clock divider value 13 get_event_counter 0x44 get the gpio.4 / cs4 / evtcntr mode and count 14 get_full_threshold 0x34 get the fifo full threshold 15 get_gpio_chip_select 0x24 get the chip select enable state for all channels 16 get_gpio_mode_and_level 0x22 get the gpio pin level and output mode values for all pins 17 get_gpio_values 0x20 get the gpio pin level for all pins 18 get_rtr_state 0x36 get the readwithrtr active state 19 get_spi_word 0x30 get the spi control word for all channels 20 get_spi_delay 0x32 get the spi delays for the specified channel 22 get_readonly_version 0x11 get device read-only version 24 reset_device 0x10 reset the device 24 set_clock_divider 0x47 set the gpio.5 / cs5 / clkout clock divider value 25 set_event_counter 0x45 set the gpio.4 / cs4 / evtcntr mode and count 26 set_full_threshold 0x35 set the fifo full threshold 27 set_gpio_chip_select 0x25 set the chip select enable state for a single channel 28 set_gpio_mode_and_level 0x23 set the gpio pin level and output mode for a single pin 29 set_gpio_values 0x21 set the gpio pin level for all pins specified using a mask 30 set_rtr_stop 0x37 abort current readwithrtr command 31 set_spi_word 0x31 set the spi control word for a single channel 32 set_spi_delay 0x33 set the spi delays for a single channel 33
AN792 rev. 0.3 13 6.1. get_clock_divid er (command id 0x46) 6.1.1. description get the gpio.5 / cs5 / clkout clock divider value. 6.1.2. setup stage (out transfer) 6.1.3. data stage (in transfer) 6.1.4. remarks and related commands gpio.5 / cs5 / clkout must be configured in clkout mode in order to generate the clock output. the output frequency is configurable thr ough the use of the clock divider. when the divider is set to 0, the output frequency is 93.75 khz. for divider values between 1 and 25 5, the output frequency is determined by the formula: see also set_clock_divider (command id 0x47). name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x46 command id wlength 0x0001 data stage length in bytes name offset size value description divider 0 1 value the gpio.5 / cs5 / clkout clock divider value. a value of 0 indicates a divider value of 256. gpio.5 clock frequency 24 mhz divider -------------------- - =
AN792 14 rev. 0.3 6.2. get_event_c ounter (command id 0x44) 6.2.1. description get the gpio.4 / cs4 / evtcntr mode and count. 6.2.2. setup stage (out transfer) 6.2.3. data stage (in transfer) 6.2.4. mode bitmap 6.2.5. remarks and related commands gpio.4 / cs4 / evtcntr must be configured in evtcntr mode to use the event counter. see also set_event_counter (command id 0x45). name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x44 command id wlength 0x0003 data stage length in bytes name offset size value description mode 0 1 bitmap event counter mode count 1 2 value the event count (big-endian) bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 overflow reserved mode bit name description 7 overflow overflow flag 0: event count did not overflow 1: event count did overflow 6:3 reserved 2:0 mode event counter mode 000?011: reserved 010: rising edge 011: falling edge 110: negative pulse 111: positive pulse
AN792 rev. 0.3 15 6.3. get_full_thres hold (command id 0x34) 6.3.1. description get the fifo full threshold. 6.3.2. setup stage (out transfer) 6.3.3. data stage (in transfer) 6.3.4. remarks and related commands see also set_full_threshold (command id 0x35). name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x34 command id wlength 0x0001 data stage length in bytes name offset size value description threshold 0 1 value the fifo full threshold. default is 128 bytes.
AN792 16 rev. 0.3 6.4. get_gpio_chip_ select (command id 0x24) 6.4.1. description get the chip select enable state for all spi channels (0 ?10). when a chip select is enabled for a channel, the corresponding cs0 ?cs10 pin will be asserted during spi transfers. 6.4.2. setup stage (out transfer) 6.4.3. data stage (in transfer) 6.4.4. channel cs enable bitmap 6.4.5. pin cs enable bitmap 6.4.6. remarks and related commands the channel chip select bitmap and the pin chip select bitmap both convey the same information in two different formats. for example if the ch 10 ch ip select is enabled, then the cs10 chip select is also enabled. see also set_gpio_chip_select (command id 0x25). name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x24 command id wlength 0x0004 data stage length in bytes name offset size value description channel cs enable 0 2 bitmap channel chip select enable bit: 0: chip select for channel disabled 1: chip select for channel enabled pin cs enable 2 2 bitmap pin chip select enable bit: 0: chip select for csn pin disabled 1: chip select for csn pin enabled offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 reserved ch 10 ch 9 ch 8 1 ch 7ch 6ch 5ch 4ch 3ch 2ch 1ch 0 offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 reserved cs10 cs9 cs8 cs7 cs6 reserved cs5 1cs4 cs3 cs2 cs1 cs0 reserved
AN792 rev. 0.3 17 6.5. get_gpio_mode_and _level (command id 0x22) 6.5.1. description get the gpio pin level and output mode for all pins. 6.5.2. setup stage (out transfer) 6.5.3. data stage (in transfer) 6.5.4. level / mode bitmap 6.5.5. remarks and related commands see also set_gpio_mode_and_level (command id 0x23). name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x22 command id wlength 0x0004 data stage length in bytes name offset size value description level 0 2 bitmap gpio pin level bit: 0: pin is logic low 1: pin is logic high mode 2 2 bitmap gpio pin output mode bit: 0: open-drain 1: push-pull offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 gpio.4 gpio.3 gpio.2 gpio.1 gpio.0 reserved 1 reserved gpio.10 gpio.9 gpio.8 gpio.7 gpio.6 reserved gpio.5
AN792 18 rev. 0.3 6.6. get_gpio_val ues (command id 0x20) 6.6.1. description get the gpio pin level for all pins. 6.6.2. setup stage (out transfer) 6.6.3. data stage (in transfer) 6.6.4. level bitmap 6.6.5. remarks and related commands see also set_gpio_values (command id 0x21). name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x20 command id wlength 0x0002 data stage length in bytes name offset size value description level 0 2 bitmap gpio pin level bit: 0: pin is logic low 1: pin is logic high offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 reserved gpio.10 gpio.9 gpio.8 gpio.7 gpio.6 reserved gpio.5 1 gpio.4 gpio.3 gpio.2 gpio.1 gpio.0 reserved
AN792 rev. 0.3 19 6.7. get_rtr_state (command id 0x36) 6.7.1. description get the readwithrtr active state. 6.7.2. setup stage (out transfer) 6.7.3. data stage (in transfer) 6.7.4. remarks and related commands this command can be sent during a data transfer comm and. if a readwithrtr data transfer command is currently active, then the active byte will return 0x01. once it has been de termined that a readwithrt r is active, it is then possible to cancel the readwithrtr by sending the set_rtr_stop (command id 0x37) command. see also set_rtr_stop (command id 0x37). name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x36 command id wlength 0x0001 data stage length in bytes name offset size value description active 0 1 value readwithrtr active: 0x00: readwithrtr mode is not active 0x01: readwithrtr mode is active
AN792 20 rev. 0.3 6.8. get_spi_word (command id 0x30) 6.8.1. description get the spi control word for all channels. 6.8.2. setup stage (out transfer) 6.8.3. data stage (in transfer) name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x30 command id wlength 0x000b data stage length in bytes name offset size value description channel 0 word 0 1 bitmap spi channel word channel 1 word 1 1 channel 2 word 2 1 channel 3 word 3 1 channel 4 word 4 1 channel 5 word 5 1 channel 6 word 6 1 channel 7 word 7 1 channel 8 word 8 1 channel 9 word 9 1 channel 10 word 10 1
AN792 rev. 0.3 21 6.8.4. channel n word bitmap 6.8.5. remarks and related commands see also set_spi_word (command id 0x31). bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reserved phase polarity mode clock bit name description 7:6 reserved 5 phase clock phase 0: leading edge 1: trailing edge 4 polarity clock polarity 0: idle low 1: idle high 3mode chip select pin mode 0: open-drain 1: push-pull 2:0 clock clock frequency 000: 12 mhz 001: 6 mhz 010: 3 mhz 011: 1.5 mhz 100: 750 khz 101: 375 khz 110: 187.5 khz 111: 93.8 khz
AN792 22 rev. 0.3 6.9. get_spi_delay (command id 0x32) 6.9.1. description get the spi delays for the specified channel. 6.9.2. setup stage (out transfer) 6.9.3. data stage (in transfer) name value description bmrequesttype 0xc0 device-to-host vendor request brequest 0x32 command id windex value spi channel to query (0?10) wlength 0x0008 data stage length in bytes name offset size value description channel 0 1 value spi channel: 0?10: channel 0?channel 10 mask 1 1 bitmap spi delay enable mask inter-byte delay 2 2 value inter-byte spi delay in 10 s units (big-endian) post-assert delay 4 2 value post-assert spi delay in 10 s units (big-endian) pre-deassert delay 6 2 value pre-deassert spi delay in 10 s units (big-endian)
AN792 rev. 0.3 23 6.9.4. mask bitmap 6.9.5. remarks and related commands refer to the cp2130 data sheet for mo re information regarding spi delays. see also set_spi_delay (command id 0x33). bit 7 bit 6 bit 5 bit 4 b it 3 bit 2 bit 1 bit 0 reserved toggle pre-deassert post-assert inter-byte bit name description 7:4 reserved 3 toggle cs toggle enable 0: disable cs toggle 1: enable cs toggle 2 pre-deassert pre-deassert delay enable 0: disable pre-deassert spi delay 1: enable pre-deassert spi delay 1 post-assert post-assert delay enable 0: disable post-assert spi delay 1: enable post-assert spi delay 0 inter-byte inter-byte delay enable 0: disable post-assert spi delay 1: enable post-assert spi delay
AN792 24 rev. 0.3 6.10. get_readonly_version (command id 0x11) 6.10.1. description get the device read-only version. 6.10.2. setup stage (out transfer) 6.10.3. data stage (in transfer) 6.10.4. remarks the device read-only version number reports the cp213 0 hardware version number. this version cannot be modified by the user. this document is compatible with version 1.0. 6.11. reset_devi ce (command id 0x10) 6.11.1. description reset the device. 6.11.2. setup stage (out transfer) 6.11.3. remarks this command is a host-to-de vice request with no data stage. approximately one m illisecond after receiving this request, the device will reset a nd re-enumerate on the usb host. name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x11 command id wlength 0x0002 data stage length in bytes name offset size value description major version 0 1 0x01 major read-only version number minor version 1 1 0x00 minor read-only version number name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x10 command id wlength 0x0000 data stage length in bytes
AN792 rev. 0.3 25 6.12. set_clock_divider (command id 0x47) 6.12.1. description set the gpio.5 / cs5 / clkout clock divider value. 6.12.2. setup stage (out transfer) 6.12.3. data stage (out transfer) 6.12.4. remarks a nd related commands gpio.5 / cs5 / clkout must be configured in clkout mode in order to generate the clock output. the output frequency is configurable thr ough the use of the clock divider. when the divider is set to 0, the output frequency is 93.75 khz. for divider values between 1 and 25 5, the output frequency is determined by the formula: see also get_clock_divider (command id 0x46). name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x47 command id wlength 0x0001 data stage length in bytes name offset size value description divider 0 1 value the gpio.5 / cs5 / clkout clock divider value. a value of 0 indicates a divider value of 256. gpio.5 clock frequency 24 mhz divider -------------------- - =
AN792 26 rev. 0.3 6.13. set_event_counter (command id 0x45) 6.13.1. description set the gpio.4 / cs4 / evtcntr mode and count. 6.13.2. setup stage (out transfer) 6.13.3. data stage (out transfer) 6.13.4. mode bitmap 6.13.5. remarks a nd related commands gpio.4 / cs4 / evtcntr must be configured in evtcntr mode to use the event counter. see also get_event_counter (command id 0x44). name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x45 command id wlength 0x0003 data stage length in bytes name offset size value description mode 0 1 bitmap event counter mode count 1 2 value the event count (big-endian) bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reserved mode bit name description 7:3 reserved must be 00000 2:0 mode event counter mode 000?011: reserved 010: rising edge 011: falling edge 110: negative pulse 111: positive pulse
AN792 rev. 0.3 27 6.14. set_full_threshold (command id 0x35) 6.14.1. description set the fifo full threshold. 6.14.2. setup stage (out transfer) 6.14.3. data stage (out transfer) 6.14.4. remarks a nd related commands see also get_full_threshold (command id 0x34). name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x35 command id wlength 0x0001 data stage length in bytes name offset size value description threshold 0 1 value the fifo full threshold. default is 128 bytes.
AN792 28 rev. 0.3 6.15. set_gpio_chip_se lect (command id 0x25) 6.15.1. description set the chip select enable state for the specified channel. when a chip select is enabled for a channel, the corresponding cs0 ?cs10 pin will be asserted during spi transfers and the spi word fo r the specified channel will be used to configure the spi. 6.15.2. setup stage (out transfer) 6.15.3. data stage (out transfer) 6.15.4. remarks a nd related commands multiple chip selects can be enabled by sending this command with control set to 0x01. sending this command with control set to 0x01 or 0x02 also sets the active spi channel to the chann el specified. this means that the last chip select enabled determines which spi word setting to use based on channel number. the set_spi_word (command id 0x31) command can be us ed to specify the spi configuration for each channel. the set_gpio_chip_select (command id 0x25) command can then be used to se lect the active channel. see also get_gpio_chip_se lect (command id 0x24). name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x25 command id wlength 0x0002 data stage length in bytes name offset size value description channel 0 1 value chip select channel (0?10) control 1 1 value chip select channel control: 0x00: specified chip select is disabled 0x01: specified chip select is enabled during spi transfers 0x02: specified chip se lect is enabled during spi transfers; all other chip selects are disabled
AN792 rev. 0.3 29 6.16. set_gpio_mode_and_ level (command id 0x23) 6.16.1. description set the gpio pin level and output mode for the specified pin. 6.16.2. setup stage (out transfer) 6.16.3. data stage (out transfer) 6.16.4. remarks a nd related commands this command can override the gpio pin modes programmed in the otp rom configuration. however the gpio pin function cannot be overridden. see also get_gpio_mode_and_level (command id 0x22). name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x23 command id wlength 0x0003 data stage length in bytes name offset size value description index 0 1 value gpio pin index (0?10) mode 1 1 value the gpio pin mode: 0x00: input 0x01: open-drain output 0x02: push-pull output level 2 1 value the gpio pin level: 0x00: logic low 0x01: logic high
AN792 30 rev. 0.3 6.17. set_gpio_val ues (command id 0x21) 6.17.1. description set the gpio pin level for all pins specified using a mask 6.17.2. setup stage (out transfer) 6.17.3. data stage (out transfer) 6.17.4. level / mask bitmap 6.17.5. remarks a nd related commands see also get_gpio_values (command id 0x20). name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x21 command id wlength 0x0004 data stage length in bytes name offset size value description level 0 2 bitmap gpio pin level bit: 0: pin is logic low 1: pin is logic high mask 2 2 bitmap gpio pin mask bit: 0: pin level is ignored 1: pin level is set offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 reserved gpio.10 gpio.9 gpio.8 gpio.7 gpio.6 reserved gpio.5 1 gpio.4 gpio.3 gpio.2 gpio.1 gpio.0 reserved
AN792 rev. 0.3 31 6.18. set_rtr_stop (command id 0x37) 6.18.1. description abort the current re adwithrtr command. 6.18.2. setup stage (out transfer) 6.18.3. data stage (out transfer) 6.18.4. remarks a nd related commands see also get_rtr_state (command id 0x36). name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x37 command id wlength 0x0001 data stage length in bytes name offset size value description abort 0 1 value abort readwithrtr: 0x00: no effect 0x01: abort current readwithrtr command
AN792 32 rev. 0.3 6.19. set_spi_word (command id 0x31) 6.19.1. description set the spi control word for a single channel. 6.19.2. setup stage (out transfer) 6.19.3. data stage (out transfer) 6.19.4. channel word bitmap 6.19.5. remarks a nd related commands see also get_spi_word (command id 0x30). name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x31 command id wlength 0x0002 data stage length in bytes name offset size value description channel 0 1 value spi channel: 0?10: channel 0?channel 10 channel word 1 1 bitmap spi channel word bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reserved phase polarity mode clock bit name description 7:6 reserved 5 phase clock phase 0: leading edge 1: trailing edge 4 polarity clock polarity 0: idle low 1: idle high 3mode chip select pin mode 0: open-drain 1: push-pull 2:0 clock clock frequency 000: 12 mhz 001: 6 mhz 010: 3 mhz 011: 1.5 mhz 100: 750 khz 101: 375 khz 110: 187.5 khz 111: 93.8 khz
AN792 rev. 0.3 33 6.20. set_spi_delay (command id 0x33) 6.20.1. description set the spi delays for the specified channel. 6.20.2. setup stage (out transfer) 6.20.3. data stage (out transfer) name value description bmrequesttype 0x40 host-to -device vendor request brequest 0x33 command id wlength 0x0008 data stage length in bytes name offset size value description channel 0 1 value spi channel to configure: 0?10: channel 0?channel 10 mask 1 1 bitmap spi delay enable mask inter-byte delay 2 2 value inter-byte spi delay in 10 s units (big-endian) post-assert delay 4 2 value post-assert spi delay in 10 s units (big-endian) pre-deassert delay 6 2 value pre-deassert spi delay in 10 s units (big-endian)
AN792 34 rev. 0.3 6.20.4. mask bitmap 6.20.5. remarks a nd related commands refer to the cp2130 data sheet for mo re information regarding spi delays. see also get_spi_dela y (command id 0x32). bit 7 bit 6 bit 5 bit 4 b it 3 bit 2 bit 1 bit 0 reserved toggle pre-deassert post-assert inter-byte bit name description 7:4 reserved 3 toggle cs toggle enable 0: disable cs toggle 1: enable cs toggle 2 pre-deassert pre-deassert delay enable 0: disable pre-deassert spi delay 1: enable pre-deassert spi delay 1 post-assert post-assert delay enable 0: disable post-assert spi delay 1: enable post-assert spi delay 0 inter-byte inter-byte delay enable 0: disable post-assert spi delay 1: enable post-assert spi delay
AN792 rev. 0.3 35 7. otp rom configuration commands (control transfers) otp rom stores configuration options that are persistent across power-on reset and all other resets. after reset, the cp2130 configures parameters according to values programmed in the otp rom. after otp settings are initialized, runtime parameters may be then be configured, altering the configuration of the device until the next reset. otp rom configuration options can only be programmed a single time. all cp2130 otp rom configuration commands are implemen ted using vendor-specific control transfers on the usb control endpoint (endpoint 0). these commands consist of a command id, command-dependent arguments, and return data for get requests. a summary of these commands is given in table 6 with detailed descriptions in the following sections. table 6. otp rom configuration commands command name command id comment page get_lock_byte 0x6e get the lo ck byte, which locks the specified fields to prevent them from being programmed 36 get_manufacturing_stri ng_1 0x62 get the usb manufacturing string descriptor (1 of 2) 37 get_manufacturing_stri ng_2 0x64 get the usb manufacturing string descriptor (2 of 2) 38 get_pin_config 0x6c get the pin configuration values 39 get_product_string_1 0x66 get the usb pr oduct string descriptor (1 of 2) 47 get_product_string_2 0x68 get the usb pr oduct string descriptor (2 of 2) 48 get_prom_config 0x70 get raw otp rom configuration information in blocks 49 get_serial_string 0x6a get the usb serial string descriptor 50 get_usb_config 0x60 get the usb configuration values 51 set_lock_byte 0x6f set the lock byte, wh ich locks the specified fields to prevent them from being programmed 52 set_manufacturing_string_1 0x63 set the usb ma nufacturing string descriptor (1 of 2) 53 set_manufacturing_string_2 0x65 set the usb ma nufacturing string descriptor (2 of 2) 54 set_pin_config 0x6d set the pin configuration values 55 set_product_string_1 0x67 set the usb product string descriptor (1 of 2) 63 set_product_string_2 0x69 set the usb product string descriptor (2 of 2) 64 set_prom_config 0x71 set ra w otp rom configuration information in blocks 65 set_serial_string 0x6b set the us b serial string descriptor 66 set_usb_config 0x61 set the usb configuration values 67
AN792 36 rev. 0.3 7.1. get_lock_byte (command id 0x6e) 7.1.1. description get the lock byte, which locks the specified fi elds to prevent them from being programmed. 7.1.2. setup stage (out transfer) 7.1.3. data stage (in transfer) 7.1.4. lock bitmap 7.1.5. remarks and related commands fields that are unlocked may be programmed by sending the appropri ate otp rom configuration command. once a field has been programmed, the lock bit for the fi eld is set to ?0?, prevent ing future programming. the default value for the field may be locked by sending this command and specifying the field as locked. see also set_lock_byte (command id 0x6f). name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x6e command id wlength 0x0002 data stage length in bytes name offset size value description lock 0 2 bitmap lock byte bitmap bit: 0: field is locked 1: field is unlocked offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 transfer priority manufacturing string 1 manufacturing string 2 release version power mode max power pid vid 1 reserved pin config serial string product string 2 product string 1
AN792 rev. 0.3 37 7.2. get_manufacturing_string1 (command id 0x62) 7.2.1. description get the usb manufactu ring string descriptor (1 of 2). 7.2.2. setup stage (out transfer) 7.2.3. data stage (in transfer) 7.2.4. remarks and related commands this command returns the string descriptor length, descript or type, and the first 61 bytes of the unicode string as specified in the usb 2.0 specification. the cp2130 usb ma nufacturing string descriptor has a maximum length of 126 bytes, including string descriptor length and descri ptor type. this means the unicode string has a maximum length of 124 bytes or 62, 16-bit unicode characters. the string descriptor length can be used to deter mine the number of valid bytes in the unicode string. the usb language id, returned in usb string descriptor 0, is defined as 0x0409 (little- endian) or english (united states). all usb strings must be spec ified according to this language id. see also: ? get_manufacturing_string2 (command id 0x64) ? set_manufacturing_string1 (command id 0x63) ? set_manufacturing_string2 (command id 0x65) name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x62 command id wlength 0x0040 data stage length in bytes name offset size value description length 0 1 value the usb str ing descriptor length in cluding length, descrip- tor type, and string descriptor type 1 1 0x03 usb string descriptor constant string 2 61 unicode utf-16 encoded st ring (little-endian; bytes 0?60) reserved 63 1 value
AN792 38 rev. 0.3 7.3. get_manufacturing_string2 (command id 0x64) 7.3.1. description get the usb manufactu ring string descriptor (2 of 2). 7.3.2. setup stage (out transfer) 7.3.3. data stage (in transfer) 7.3.4. remarks and related commands this command returns the last 63 bytes of the unic ode string in the string descriptor. the cp2130 usb manufacturing string descriptor has a maximum length of 126 bytes, including string descriptor length and descriptor type. this means the un icode string has a maximum length of 124 bytes or 62, 16-bit unicode characters. the string descriptor length can be used to deter mine the number of valid bytes in the unicode string. the usb language id, returned in usb string descriptor 0, is defined as 0x0409 (little- endian) or english (united states). all usb strings must be spec ified according to this language id. see also: ? get_manufacturing_string1 (command id 0x62) ? set_manufacturing_string1 (command id 0x63) ? set_manufacturing_string2 (command id 0x65) name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x64 command id wlength 0x0040 data stage length in bytes name offset size value description string 0 63 unicode utf-16 encoded stri ng (little-endian; bytes 61?123) reserved 63 1 value
AN792 rev. 0.3 39 7.4. get_pin_config (command id 0x6c) 7.4.1. description get the pin configuration values. 7.4.2. setup stage (out transfer) 7.4.3. data stage (in transfer) name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x6c command id wlength 0x0014 data stage length in bytes name offset size value description gpio.0 0 1 value gpio.0 / cs0 pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs0 (push-pull output) gpio.1 1 1 value gpio.1 / cs1 pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs1 (push-pull output) gpio.2 2 1 value gpio.2 / cs2 pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs2 (push-pull output) gpio.3 3 1 value gpio.3 / cs3 / rtr pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs3 (push-pull output) 0x04: rtr (input) 0x05: rtr (input)
AN792 40 rev. 0.3 gpio.4 4 1 value gpio.4 / cs4 / evtcntr pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs4 (push-pull output) 0x04: evtcntr rising edge (input) 0x05: evtcntr falling edge (input) 0x06: evtcntr negative pulse (input) 0x07: evtcntr positive pulse (input) gpio.5 5 1 value gpio.5 / cs5 / clkout pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs5 (push-pull output) 0x04: clkout (push-pull output) gpio.6 6 1 value gpio.6 / cs6 pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs6 (push-pull output) gpio.7 7 1 value gpio.7 / cs7 pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs7 (push-pull output) gpio.8 8 1 value gpio.8 / cs8 / spiact pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs8 (push-pull output) 0x04: spiact (push-pull output) gpio.9 9 1 value gpio.9 / cs9 / suspend pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs9 (push-pull output) 0x04: suspend (push-pull output) gpio.10 10 1 value gpio.10 / cs10 / suspend pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs10 (push-pull output) 0x04: suspend (push-pull output) name offset size value description
AN792 rev. 0.3 41 suspend level 11 2 bitmap suspend pin level suspend mode 13 2 bitmap suspend pin mode wakeup mask 15 2 bitmap wakeup pin mask wakeup match 17 2 bitmap wakeup pin match divider 19 1 value the gpio.5 / cs5 / clkout otp rom clock divider value after reset. a value of 0 indicates a divider value of 256. name offset size value description
AN792 42 rev. 0.3 7.4.4. suspend level bitmap offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 reserved gpio.10 gpio.9 gpio.8 gpio.7 gpio.6 vpp gpio.5 1 gpio.4 gpio.3 gpio.2 gpio.1 gpio.0 mosi miso sck offset bit name description 0 7 reserved 6gpio.10 suspend pin level 0: logic low 1: logic high 5gpio.9 4gpio.8 3gpio.7 2gpio.6 1 vpp 0gpio.5 1 7gpio.4 6gpio.3 5gpio.2 4gpio.1 3gpio.0 2mosi 1miso 0sck
AN792 rev. 0.3 43 7.4.5. suspend mode bitmap offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 enable gpio.10 gpio.9 gpio.8 gpio.7 gpio.6 vpp gpio.5 1 gpio.4 gpio.3 gpio.2 gpio.1 gpio.0 mosi miso sck offset bit name description 0 7 enabled suspend mode and level enable 0: don?t use suspend mode and levels 1: use suspend mode and levels 6gpio.10 suspend pin mode 0: open-drain 1: push-pull 5gpio.9 4gpio.8 3gpio.7 2gpio.6 1 vpp 0gpio.5 1 7gpio.4 6gpio.3 5gpio.2 4gpio.1 3gpio.0 2mosi 1miso 0sck
AN792 44 rev. 0.3 7.4.6. wakeup mask bitmap offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 reserved gpio.10 gpio.9 gpio.8 gpio.7 gpio.6 vpp gpio.5 1 gpio.4 gpio.3 gpio.2 gpio.1 gpio.0 mosi miso sck offset bit name description 0 7 reserved must be 0 6gpio.10 suspend pin mode 0: open-drain 1: push-pull 5gpio.9 4gpio.8 3gpio.7 2gpio.6 1 vpp 0gpio.5 1 7gpio.4 6gpio.3 5gpio.2 4gpio.1 3gpio.0 2mosi 1miso 0sck
AN792 rev. 0.3 45 7.4.7. wakeup match bitmap offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 reserved gpio.10 gpio.9 gpio.8 gpio.7 gpio.6 vpp gpio.5 1 gpio.4 gpio.3 gpio.2 gpio.1 gpio.0 mosi miso sck offset bit name description 0 7 reserved 6gpio.10 suspend pin mode 0: open-drain 1: push-pull 5gpio.9 4gpio.8 3gpio.7 2gpio.6 1 vpp 0gpio.5 1 7gpio.4 6gpio.3 5gpio.2 4gpio.1 3gpio.0 2mosi 1miso 0sck
AN792 46 rev. 0.3 7.4.8. remarks and related commands the clock divider value is used during initializatio n after reset. the set_clock_divider (command id 0x47) command can be used to override the value after initialization. this command always returns the divider value stored in the otp rom, not the runtime divider value. send the get_clock_divider (command id 0x46) command to obtain the runtime divider value. any pin (gpio.0?gpio.10) may be used to generate a usb remote wakeup event. the wakeup mask specifies which pins may be used to generate a wakeup event. the wakeup match value specifies the pin values such that if any pin selected in the wa keup mask does not ma tch the wakeup match value, the device will generate a usb remote wakeup event when the device is suspended. once a gpio pin function has been se t in the otp rom, the pin function ca nnot be changed, but the output mode (push-pull or open-drain) may be overridden at runtime with the set_gpio_chip_select (command id 0x25) and set_gpio_mode_and_level (command id 0x23) commands. refer to the cp2130 data sheet fo r full pin function descriptions. see also set_pin_config (command id 0x6d).
AN792 rev. 0.3 47 7.5. get_product_st ring1 (command id 0x66) 7.5.1. description get the usb product string descriptor (1 of 2). 7.5.2. setup stage (out transfer) 7.5.3. data stage (in transfer) 7.5.4. remarks and related commands this command returns the string descriptor length, descript or type, and the first 61 bytes of the unicode string as specified in the usb 2.0 specification. the cp2130 u sb product string descriptor has a maximum length of 126 bytes, including string descriptor lengt h and descriptor type. this means the unicode string has a maximum length of 124 bytes or 62, 16-bit unicode characters. the string descriptor length can be used to deter mine the number of valid bytes in the unicode string. the usb language id, returned in usb string descriptor 0, is defined as 0x0409 (little- endian) or english (united states). all usb strings must be spec ified according to this language id. see also: ? get_product_string2 (command id 0x68) ? set_product_string1 (command id 0x67) ? set_product_string2 (command id 0x69) name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x66 command id wlength 0x0040 data stage length in bytes name offset size value description length 0 1 value the usb str ing descriptor length in cluding length, descrip- tor type, and string descriptor type 1 1 0x03 usb string descriptor constant string 2 61 unicode utf-16 encoded st ring (little-endian; bytes 0?60) reserved 63 1 value
AN792 48 rev. 0.3 7.6. get_product_st ring2 (command id 0x68) 7.6.1. description get the usb product string descriptor (2 of 2). 7.6.2. setup stage (out transfer) 7.6.3. data stage (in transfer) 7.6.4. remarks and related commands this command returns the last 63 bytes of the unicode string in the string descriptor. the cp2130 usb product string descriptor has a maximum length of 126 bytes, incl uding string descriptor length and descriptor type. this means the unicode string has a maximum length of 124 bytes or 62, 16-bit unicode characters. the string descriptor length can be used to deter mine the number of valid bytes in the unicode string. the usb language id, returned in usb string descriptor 0, is defined as 0x0409 (little- endian) or english (united states). all usb strings must be spec ified according to this language id. see also: ? get_product_string1 (command id 0x66) ? set_product_string1 (command id 0x67) ? set_product_string2 (command id 0x69) name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x68 command id wlength 0x0040 data stage length in bytes name offset size value description string 0 63 unicode utf-16 encoded stri ng (little-endian; bytes 61?123) reserved 63 1 value
AN792 rev. 0.3 49 7.7. get_prom_conf ig (command id 0x70) 7.7.1. description get the otp rom configurat ion information in blocks. 7.7.2. setup stage (out transfer) 7.7.3. data stage (in transfer) 7.7.4. remarks and related commands this command can be used to read the entire otp rom configuration as a byte array. the otp rom configuration consists of 512 bytes of data. this data is broken into 8, 64-byte blocks. each block is indexed from 0 to 7. send this command 8 times with block index 0?7 to retrieve the entire otp rom configuration. the otp rom is detailed in "appendix a?otp rom format" on page 73. see also set_prom_config (command id 0x71). name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x70 command id windex value block index (0?7). wlength 0x0040 data stage length in bytes name offset size value description block 0 64 array returns the requested otp rom block data
AN792 50 rev. 0.3 7.8. get_serial_string (command id 0x6a) 7.8.1. description get the usb serial string descriptor. 7.8.2. setup stage (out transfer) 7.8.3. data stage (in transfer) 7.8.4. remarks and related commands this command returns the strin g descriptor length, descriptor type, and 60 bytes of the unicode string as specified in the usb 2.0 specification. the cp2130 usb serial string descriptor has a maximum le ngth of 62 bytes, including string descriptor length and descriptor type. this means the unicode string has a maximum length of 60 bytes or 30, 16-bit unicode characters. the string descriptor length can be used to deter mine the number of valid bytes in the unicode string. the usb language id, returned in usb string descriptor 0, is defined as 0x0409 (little- endian) or english (united states). all usb strings must be spec ified according to this language id. see also set_serial_string (command id 0x6b). name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x6a command id wlength 0x0040 data stage length in bytes name offset size value description length 0 1 value the usb str ing descriptor length in cluding length, descrip- tor type, and string descriptor type 1 1 0x03 usb string descriptor constant string 2 60 unicode utf-16 encoded st ring (little-endian; bytes 0?59) reserved 62 2 value
AN792 rev. 0.3 51 7.9. get_usb_config (command id 0x60) 7.9.1. description get the usb configuration values. 7.9.2. setup stage (out transfer) 7.9.3. data stage (in transfer) 7.9.4. remarks and related commands the usb configuration values affect the usb descriptors returned during usb enumeration. the device must be reset to apply these values. see "2.1. data transfer priority" on page 4 for mo re information regarding data transfer priority. see also set_usb_config (command id 0x61). name value description bmrequesttype 0xc0 device- to-host vendor request brequest 0x60 command id wlength 0x0009 data stage length in bytes name offset size value description vid 0 2 value usb vendor id (little-endian) pid 2 2 value usb product id (little-endian) max power 4 1 value power required from the host in bus-powered mode: 0?250: max electrical cu rrent in units of 2 ma power mode 5 1 value power mode: 0x00: usb bus-powered; voltage regulator enabled 0x01: usb self-powered; voltage regulator disabled 0x02: usb self-powered; voltage regulator enabled major release 6 1 value usb device major release number (bcd) minor release 7 1 value usb device minor release number (bcd) transfer priority 8 1 value data transfer priority: 0x00: high-priority read 0x01: high-priority write
AN792 52 rev. 0.3 7.10. set_lock_byte (command id 0x6f) 7.10.1. description set the lock byte, which locks the specified fields to prevent them from being programmed. 7.10.2. setup stage (out transfer) 7.10.3. data stage (out transfer) 7.10.4. lock bitmap 7.10.5. remarks a nd related commands fields that are unlocked may be programmed by sending the appropri ate otp rom configuration command. once a field has been programmed, the lock bit for the fi eld is set to ?0?, prevent ing future programming. the default value for the field may be locked by sending this command and specifying the field as locked. the wvalue field must be set to the memory key value in order to write to otp memory. for all other commands, the wvalue field should be cl eared to 0 to reduce the risk of otp memory corruption. see also get_lock_byte (command id 0x6e). name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x6f command id wvalue 0xa5f1 memory key wlength 0x0002 data stage length in bytes name offset size value description lock 0 2 bitmap lock byte bitmap bit: 0: field is locked 1: field is unlocked offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 transfer priority manufacturing string 1 manufacturing string 2 release version power mode max power pid vid 1 reserved pin config serial string product string 2 product string 1
AN792 rev. 0.3 53 7.11. set_manufacturing_ string1 (command id 0x63) 7.11.1. description set the usb manufacturing str ing descriptor (1 of 2). 7.11.2. setup stage (out transfer) data stage (out transfer) 7.11.3. remarks an d related commands this command sets the string descript or length, descriptor type, and the fi rst 61 bytes of the unicode string as specified in the usb 2.0 specification. the cp2130 usb ma nufacturing string descriptor has a maximum length of 126 bytes, including string descriptor length and descri ptor type. this means the unicode string has a maximum length of 124 bytes or 62, 16-bit unicode characters. the string descriptor length specifies the nu mber of valid bytes in the unicode string. the usb language id, returned in usb string descriptor 0, is defined as 0x0409 (little- endian) or english (united states). all usb strings must be spec ified according to this language id. the wvalue field must be set to the memory key value in order to write to otp memory. for all other commands, the wvalue field should be cl eared to 0 to reduce the risk of otp memory corruption. see also: ? get_manufacturing_string1 (command id 0x62) ? get_manufacturing_string2 (command id 0x64) ? set_manufacturing_string2 (command id 0x65) name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x63 command id wvalue 0xa5f1 memory key wlength 0x0040 data stage length in bytes name offset size value description length 0 1 value the usb str ing descriptor length in cluding length, descrip- tor type, and string descriptor type 1 1 0x03 usb string descriptor constant string 2 61 unicode utf-16 encoded st ring (little-endian; bytes 0?60) reserved 63 1 value
AN792 54 rev. 0.3 7.12. set_manufacturing_string2 (command id 0x65) 7.12.1. description set the usb manufacturing str ing descriptor (2 of 2). 7.12.2. setup stage (out transfer) 7.12.3. data stage (out transfer) 7.12.4. remarks a nd related commands this command sets the last 63 bytes of the unicode stri ng in the string descriptor. the cp2130 usb manufacturing string descriptor has a maximum length of 126 bytes, incl uding string descriptor length and descriptor type. this means the unicode string has a maximum length of 124 bytes or 62, 16-bit unicode characters. the string descriptor length specifies the nu mber of valid bytes in the unicode string. the usb language id, returned in usb string descriptor 0, is defined as 0x0409 (little- endian) or english (united states). all usb strings must be spec ified according to this language id. the wvalue field must be set to the memory key value in order to write to otp memory. for all other commands, the wvalue field should be cl eared to 0 to reduce the risk of otp memory corruption. see also: ? get_manufacturing_string1 (command id 0x62) ? get_manufacturing_string2 (command id 0x64) ? set_manufacturing_string1 (command id 0x63) name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x65 command id wvalue 0xa5f1 memory key wlength 0x0040 data stage length in bytes name offset size value description string 0 63 unicode utf-16 encoded stri ng (little-endian; bytes 61?123) reserved 63 1 value
AN792 rev. 0.3 55 7.13. set_pin_config (command id 0x6d) 7.13.1. description set the pin configuration values. 7.13.2. setup stage (out transfer) 7.13.3. data stage (out transfer) name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x6d command id wvalue 0xa5f1 memory key wlength 0x0014 data stage length in bytes name offset size value description gpio.0 0 1 value gpio.0 / cs0 pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs0 (push-pull output) gpio.1 1 1 value gpio.1 / cs1 pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs1 (push-pull output) gpio.2 2 1 value gpio.2 / cs2 pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs2 (push-pull output) gpio.3 3 1 value gpio.3 / cs3 / rtr pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs3 (push-pull output) 0x04: rtr (input) 0x05: rtr (input)
AN792 56 rev. 0.3 gpio.4 4 1 value gpio.4 / cs4 / evtcntr pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs4 (push-pull output) 0x04: evtcntr rising edge (input) 0x05: evtcntr falling edge (input) 0x06: evtcntr negative pulse (input) 0x07: evtcntr positive pulse (input) gpio.5 5 1 value gpio.5 / cs5 / clkout pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs5 (push-pull output) 0x04: clkout (push-pull output) gpio.6 6 1 value gpio.6 / cs6 pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs6 (push-pull output) gpio.7 7 1 value gpio.7 / cs7 pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs7 (push-pull output) gpio.8 8 1 value gpio.8 / cs8 / spiact pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs8 (push-pull output) 0x04: spiact (push-pull output) gpio.9 9 1 value gpio.9 / cs9 / suspend pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs9 (push-pull output) 0x04: suspend (push-pull output) gpio.10 10 1 value gpio.10 / cs10 / suspend pin function: 0x00: gpio (input) 0x01: gpio (open-drain output) 0x02: gpio (push-pull output) 0x03: cs10 (push-pull output) 0x04: suspend (push-pull output) name offset size value description
AN792 rev. 0.3 57 suspend level 11 2 bitmap suspend pin level suspend mode 13 2 bitmap suspend pin mode wakeup mask 15 2 bitmap wakeup pin mask wakeup match 17 2 bitmap wakeup pin match divider 19 1 value the gpio.5 / cs5 / clkout otp rom clock divider value after reset. a value of 0 indicates a divider value of 256. name offset size value description
AN792 58 rev. 0.3 7.13.4. suspend level bitmap offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 reserved gpio.10 gpio.9 gpio.8 gpio.7 gpio.6 vpp gpio.5 1 gpio.4 gpio.3 gpio.2 gpio.1 gpio.0 mosi miso sck offset bit name description 0 7 reserved 6gpio.10 suspend pin level 0: logic low 1: logic high 5gpio.9 4gpio.8 3gpio.7 2gpio.6 1 vpp 0gpio.5 1 7gpio.4 6gpio.3 5gpio.2 4gpio.1 3gpio.0 2mosi 1miso 0sck
AN792 rev. 0.3 59 7.13.5. suspend mode bitmap offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 enable gpio.10 gpio.9 gpio.8 gpio.7 gpio.6 vpp gpio.5 1 gpio.4 gpio.3 gpio.2 gpio.1 gpio.0 mosi miso sck offset bit name description 0 7 enabled suspend mode and level enable 0: don?t use suspend mode and levels 1: use suspend mode and levels 6gpio.10 suspend pin mode 0: open-drain 1: push-pull 5gpio.9 4gpio.8 3gpio.7 2gpio.6 1 vpp 0gpio.5 1 7gpio.4 6gpio.3 5gpio.2 4gpio.1 3gpio.0 2mosi 1miso 0sck
AN792 60 rev. 0.3 7.13.6. wakeup mask bitmap offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 reserved gpio.10 gpio.9 gpio.8 gpio.7 gpio.6 vpp gpio.5 1 gpio.4 gpio.3 gpio.2 gpio.1 gpio.0 mosi miso sck offset bit name description 0 7 reserved must be 0 6gpio.10 suspend pin mode 0: open-drain 1: push-pull 5gpio.9 4gpio.8 3gpio.7 2gpio.6 1 vpp 0gpio.5 1 7gpio.4 6gpio.3 5gpio.2 4gpio.1 3gpio.0 2mosi 1miso 0sck
AN792 rev. 0.3 61 7.13.7. wakeup match bitmap offset bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 0 reserved gpio.10 gpio.9 gpio.8 gpio.7 gpio.6 vpp gpio.5 1 gpio.4 gpio.3 gpio.2 gpio.1 gpio.0 mosi miso sck offset bit name description 0 7 reserved 6gpio.10 suspend pin mode 0: open-drain 1: push-pull 5gpio.9 4gpio.8 3gpio.7 2gpio.6 1 vpp 0gpio.5 1 7gpio.4 6gpio.3 5gpio.2 4gpio.1 3gpio.0 2mosi 1miso 0sck
AN792 62 rev. 0.3 7.13.8. remarks a nd related commands the clock divider value is used during initializatio n after reset. the set_clock_divider (command id 0x47) command can be used to override the value after initialization. this command always returns the divider value stored in the otp rom, not the runtime divider value. send the get_clock_divider (command id 0x46) command to obtain the runtime divider value. any pin (gpio.0?gpio.10) may be used to generate a usb remote wakeup event. the wakeup mask specifies which pins may be used to generate a wakeup event. the wakeup match value specifies the pin values such that if any pin selected in the wa keup mask does not ma tch the wakeup match value, the device will generate a usb remote wakeup event when the device is suspended. once a gpio pin function has been se t in the otp rom, the pin function ca nnot be changed, but the output mode (push-pull or open-drain) may be overridden at runtime with the set_gpio_chip_select (command id 0x25) and set_gpio_mode_and_level (command id 0x23) commands. refer to the cp2130 data sheet fo r full pin function descriptions. the wvalue field must be set to the memory key value in order to write to otp memory. for all other commands, the wvalue field should be cl eared to 0 to reduce the risk of otp memory corruption. see also get_pin_config (command id 0x6c).
AN792 rev. 0.3 63 7.14. set_product_string1 (command id 0x67) 7.14.1. description set the usb product string descriptor (1 of 2). 7.14.2. setup stage (out transfer) 7.14.3. data stage (out transfer) 7.14.4. remarks a nd related commands this command sets the string descript or length, descriptor type, and the fi rst 61 bytes of the unicode string as specified in the usb 2.0 specification. the cp2130 u sb product string descriptor has a maximum length of 126 bytes, including string descriptor lengt h and descriptor type. this means the unicode string has a maximum length of 124 bytes or 62, 16-bit unicode characters. the string descriptor length specifies the nu mber of valid bytes in the unicode string. the usb language id, returned in usb string descriptor 0, is defined as 0x0409 (little- endian) or english (united states). all usb strings must be spec ified according to this language id. the wvalue field must be set to the memory key value in order to write to otp memory. for all other commands, the wvalue field should be cl eared to 0 to reduce the risk of otp memory corruption. see also: ? get_product_string1 (command id 0x66) ? get_product_string2 (command id 0x68) ? set_product_string2 (command id 0x69) name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x67 command id wvalue 0xa5f1 memory key wlength 0x0040 data stage length in bytes name offset size value description length 0 1 value the usb str ing descriptor length in cluding length, descrip- tor type, and string descriptor type 1 1 0x03 usb string descriptor constant string 2 61 unicode utf-16 encoded st ring (little-endian; bytes 0?60) reserved 63 1 value
AN792 64 rev. 0.3 7.15. set_product_string2 (command id 0x69) 7.15.1. description set the usb product string descriptor (2 of 2). 7.15.2. setup stage (out transfer) 7.15.3. data stage (out transfer) 7.15.4. remarks a nd related commands this command sets the last 63 bytes of the unicode string in the string descriptor. the cp2130 usb product string descriptor has a maximum length of 126 bytes, including string descriptor length and descriptor type. this means the unicode string has a maximum length of 124 bytes or 62, 16-bit unicode characters. the string descriptor length specifies the nu mber of valid bytes in the unicode string. the usb language id, returned in usb string descriptor 0, is defined as 0x0409 (little- endian) or english (united states). all usb strings must be spec ified according to this language id. the wvalue field must be set to the memory key value in order to write to otp memory. for all other commands, the wvalue field should be cl eared to 0 to reduce the risk of otp memory corruption. see also: ? get_product_string1 (command id 0x66) ? get_product_string2 (command id 0x68) ? set_product_string1 (command id 0x67) name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x69 command id wvalue 0xa5f1 memory key wlength 0x0040 data stage length in bytes name offset size value description string 0 63 unicode utf-16 encoded stri ng (little-endian; bytes 61?123) reserved 63 1 value
AN792 rev. 0.3 65 7.16. set_prom_config (command id 0x71) 7.16.1. description set the otp rom configuration information in blocks. 7.16.2. setup stage (out transfer) 7.16.3. data stage (out transfer) 7.16.4. remarks a nd related commands this command can be used to write the entire otp rom configuration as a byte array. the otp rom configuration consists of 512 bytes of data. this data is broken into 8, 64-byte blocks. each block is indexed from 0 to 7. send this command 8 times with block inde x 0?7 to write the entire otp rom configuration. the otp rom is detailed in "appendix a?otp rom format" on page 73. the wvalue field must be set to the memory key value in order to write to otp memory. for all other commands, the wvalue field should be cl eared to 0 to reduce the risk of otp memory corruption. see also get_prom_config (command id 0x70). name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x71 command id wvalue 0xa5f1 memory key windex value block index (0?7). wlength 0x0040 data stage length in bytes name offset size value description block 0 64 array writes the requested otp rom block data
AN792 66 rev. 0.3 7.17. set_serial_str ing (command id 0x6b) 7.17.1. description set the usb serial string descriptor. 7.17.2. setup stage (out transfer) 7.17.3. data stage (out transfer) 7.17.4. remarks a nd related commands this command sets the string descriptor length, descriptor type, and 60 bytes of the unicode string as specified in the usb 2.0 specification. the cp2130 usb serial string de scriptor has a maximum length of 62 bytes, including string descriptor length and descriptor type. this means the unicode string has a maximum length of 60 bytes or 30, 16-bit unicode characters. the string descriptor length specifies the nu mber of valid bytes in the unicode string. the usb language id, returned in usb string descriptor 0, is defined as 0x0409 (little- endian) or english (united states). all usb strings must be spec ified according to this language id. the wvalue field must be set to the memory key value in order to write to otp memory. for all other commands, the wvalue field should be cl eared to 0 to reduce the risk of otp memory corruption. see also get_serial_string (command id 0x6a). name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x6b command id wvalue 0xa5f1 memory key wlength 0x0040 data stage length in bytes name offset size value description length 0 1 value the usb str ing descriptor length in cluding length, descrip- tor type, and string descriptor type 1 1 0x03 usb string descriptor constant string 2 60 unicode utf-16 encoded st ring (little-endian; bytes 0?59) reserved 62 2 value
AN792 rev. 0.3 67 7.18. set_usb_config (command id 0x61) 7.18.1. description set the usb configuration values. 7.18.2. setup stage (out transfer) 7.18.3. data stage (out transfer) name value description bmrequesttype 0x40 host-to-device vendor request brequest 0x61 command id wvalue 0xa5f1 memory key wlength 0x000a data stage length in bytes name offset size value description vid 0 2 value usb vendor id (little-endian) pid 2 2 value usb product id (little-endian) max power 4 1 value power required from the host in bus-powered mode: 0?250: max electrical cu rrent in units of 2 ma power mode 5 1 value power mode: 0x00: usb bus-powered; voltage regulator enabled 0x01: usb self-powered; voltage regulator disabled 0x02: usb self-powered; voltage regulator enabled major release 6 1 value usb device major release number (bcd) minor release 7 1 value usb device minor release number (bcd) transfer priority 8 1 value data transfer priority: 0x00: high-priority read 0x01: high-priority write mask 9 1 bitmap mask bitmap bit: 0: do not write the field 1: write the field
AN792 68 rev. 0.3 7.18.4. mask bitmap 7.18.5. remarks a nd related commands the usb configuration values affect the usb descriptors returned during usb enumeration. the device must be reset to apply these values. see "2.1. data transfer priority" on page 4 for mo re information regarding data transfer priority. use the get_lock_byte (command id 0x6e) comman d to determine which fields can be written. the wvalue field must be set to the memory key value in order to write to otp memory. for all other commands, the wvalue field should be cl eared to 0 to reduce the risk of otp memory corruption. see also get_usb_config (command id 0x60). bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 transfer pri- ority reserved release version power mode max power pid vid
AN792 rev. 0.3 69 8. interfacing with the cp2130 using libusb for users that are not usin g a windows platform, libusb will be the ea siest way to integrate the cp2130 with a modern host os such as linux or osx. this document is accompanied by a sample c++ application that makes use of libusb to show how to set gpio values, write an d read, from the device. th is sample code should be used as an example of how to open and close the device in libusb and how to issue control requests to endpoint 0 and bulk requests to endpoint 1 or 2. 8.1. libusb and linux this section will show how to use libusb with ubuntu 12.04. the instr uctions should be simila r across most linux os distributions. for specific insta llation instructions on installation and usage, visit the libusb website at www.libusb.org . 8.1.1. installation on linux to install the driver in ubun tu linux use the advanced packaging tool ( apt-get). this will do wnload and place all the files needed for libusb in their proper loca tions. type the following command into a terminal: sudo apt-get install libusb-1.0-0-dev in order for a device to be accessible by non-root users a udev file needs to be created. th is file is included in the sample source files which allows acce ss to any silicon labs device. place the file in /et c/udev/rules.d directory. here is the functional part of the file: subsystem=="usb", attrs{idvendor}=="10c4", mode="0666" subsystem=="usb_device", attrs{idvendor}=="10c4", mode="0666" the udev file above will allo w access to any silicon labs device because it is matching off of the vid only. for more information and guidance on writing or custo mizing udev files, visit the writing page at www.reactivated.net/ writing_udev_rules.html . after performing these steps, your device can by plugged in and will be accessible via libusb. 8.1.2. usage on linux to use linusb in your application you?ll need to include th e proper header file a nd link against the libusb libraries. in this c++ example, use the included libusb header file: #include for usage in other languages, see the see the bindings section of the busb website at www.libusb.org/#bindings . to link with the linusb libraries, add th is command line switch to the linker: -lusb-1.0 8.1.3. initialization and device discovery the sample application shows the calls nece ssary to initialize an d discover a device. the steps that need to be taken to get a handle to the cp2130 device are: 1. initialize libusb using libusb_init() . 2. get the device list using libusb_get_device_list() ? and find a device to connect to. 3. open the device with libusb using libusb_open() . 4. detach any existing kernel connection by checking libusb_kernel_driver_active() ? and using libusb_detach_kernel_driver() if it is connected to the kernel. 5. claim the interface using libusb_claim_interface() . here is the program listing from the sample application with comments for reference: // initialize libusb if (libusb_init(&context) != 0) goto exit;
AN792 70 rev. 0.3 // search the connected devices to find and open a handle to the cp2130 devicecount = libusb_get_device_list(context, &devicelist); if (devicecount <= 0) goto exit; for (int i = 0; i < devicecount; i++) { if (libusb_get_device_descriptor(devicelist[i], &devicedescriptor) == 0) { if ((devicedescriptor.idvendor == 0x10c4) && (devicedescriptor.idproduct == 0x87a0)) { device = devicelist[i]; break; } } } if (device == null) { std::cout << "error: device not found" << std::endl; goto exit; } // if a device is found, then open it if (libusb_open(device, &cp2130handle) != 0) { std::cout << "error: could not open device" << std::endl; goto exit; } // see if a kernel driver is active already, if so detach it and store a // flag so we can reattach when we are done if (libusb_kernel_driver_active(cp2130handle, 0) != 0) { libusb_detach_kernel_driver(cp2130handle, 0); kernelattached = 1; } // finally, claim the interface if (libusb_claim_interface(cp2130handle, 0) != 0) { std::cout << "error: could not claim interface" << std::endl; goto exit; }
AN792 rev. 0.3 71 8.1.4. unin itialization the sample code also shows the calls necessary to uninitialize a device. the steps need to be taken to disconnect from the cp2130 device are: 1. release the interface using ? libusb_release_interface() . 2. reattach from the kernel using libusb_attach_kernel_driver() (only if the device was connected to the kernel previously). 3. close the libusb handle using libusb_close() . 4. free the device list we obtained originaly using libusb_free_device_list() . 5. uninitialize libusb using libusb_exit() . here is the program listing from the sample application for reference: // cleanup and deinitialize libusb if (cp2130handle) libusb_release_interface(cp2130handle, 0); if (kernelattached) libusb_attach_kernel_driver(cp2130handle, 0); if (cp2130handle) libusb_close(cp2130handle); if (devicelist) libusb_free_device_list(devicelist, 1); if (context) libusb_exit(context); 8.1.5. usb requests there are three types of usb requests that can be sent to the cp2130: control, bulk in, and bulk out. the control requests are used for vendor specific gen eral purpose requests to the control endpoint. the bulk pipes will allow for reading and writing data to the spi lines, miso and mosi. the sample source shows examples of each of these. 8.1.5.1. control requests the example gpio function will get/se t the gpio values with a control request. each of the commands defined in section ?6. configuration and control commands (control transfers)? ca n be used with the libusb control request function. each of the paramaters will map to the libusb function. in this example we w ill refer to section ?6.6. get_gpio_values (command id 0x20)? . in this command there is a bmrequesttype, brequest and wlength. in this case the other paramaters, wvalue and windex, are set to 0. these parameters are used dire ctly with the libusb_control_transfer_function and it will return the number of bytes tran sferred. here is the definition: int libusb_control_transfer(libusb_device_handle* dev_handle, uint8_t bmrequesttype, uint8_t brequest, uint16_t wvalue, uint16_t windex, unsigned char* data, uint16_t wlength, unsigned int timeout) after putting the defined values from section ?6.6.2. setup stage (out transfer)? in th e function, this is the resulting call to get the gpio unsigned char control_buf_out[2]; libusb_control_transfer(cp2130handle, 0xc0, 0x20, 0x0000, 0x0000, control_buf_out, s izeof (control_buf_out), usbtimeout); the function will return the data in the control_buf_out buffer and the return value will be 2, the size of that buffer. the gpio values can be read form the control_buf_out buffer as defined in section ?6.6.4. level bitmap? . all the other requests should be formatted in the same way, according to the libusb documentation .
AN792 72 rev. 0.3 8.1.5.2. bulk out requests the example write function w ill send data to the spi mosi line. to perf orm writes, use the de scription in section ?5.2. write (command id 0x01)? to tran smit data with the libusb bulk transf er function. here is the definition: int libusb_bulk_transfer(struct libusb_device_handle* dev_handle, unsigned char endpoint, unsigned char* data, int length, int * transferred, unsigned int timeout) to perform a write to the mosi line, pack a buffer with the specified data and payload then send the entire packet. here is an example from the sample applic ation that will write 6 bytes to endpoint 1: ??? ? unsigned ? char ? write_command_buf[14] ? = ? { ???????? 0x00, ? 0x00, ? // ? reserved ???????? 0x01, ? // ? write ? command ???????? 0x00, ? // ? reserved ???????? 0x06, ? 0x00, ? 0x00, ? 0x00, ? // ? write ? 6 ? bytes, ? little \ endian ???????? 0x00, ? 0x11, ? 0x22, ? 0x33, ? 0x44, ? 0x55 ? // ? test ? data, ? 6 ? bytes ???? }; ???? ???? libusb_bulk_transfer(cp2130handle, ? 0x01, ? write_command_buf, sizeof(write_command_buf), ? &byteswritten, ? usbtimeout); the function will return 0 u pon success, otherwise it will return an erro r code to check for the failure reason. 8.1.5.3. bulk in requests note: because there is no input to the spi t he read is commented out. the code itself demonstrates reading 6 bytes, but will not succeed since there is nothing to send this data to t he host. this code is meant to serve as an example of how to perform a read in a developed system. the example read function w ill send a request to read data from the spi miso line. to perform reads, use the description in section ?5.1. read (comma nd id 0x00)? to request data with the libusb bulk transfer function (see definition in ?8.1.5.2. bulk out requests? , or the libusb documentation ). to perform a read from the miso line, pack a buffer with the specified read command th en send the entire packet. immediately after that, perform another bulk request to get the response. here is an example from the sample application that will try to read 6 bytes from endpoint 1: ???? // ? this ? example ? shows ? how ? to ? issue ? a ? bulk ? read ? request ? to ? the ? spi ? miso ? line ???? unsigned ? char ? read_command_buf[14] ? = ? { ???????? 0x00, ? 0x00, ? // ? reserved ???????? 0x00, ? // ? read ? command ???????? 0x00, ? // ? reserved ???????? 0x06, ? 0x00, ? 0x00, ? 0x00, ? // ? read ? 6 ? bytes, ? little \ endian ???? }; ???? unsigned ? char ? read_input_buf[6]; ? ???? libusb_bulk_transfer(cp2130handle, ? 0x01, ? read_command_buf, ? sizeof(read_command_buf), ? &byteswritten, ? usbtimeout); ???? libusb_bulk_transfer(cp2130handle, ? 0x01, ? read_input_buf, ? sizeof(read_input_buf), ? &bytesread, ? usbtimeout)) the bulk transfer function w ill return 0 upon success, otherwi se it will return an error code to check for the failure reason. in this case make su re to check that the byteswritten is the sa me as the command buffer size as well as a successful transfer.
AN792 rev. 0.3 73 a ppendix a?otp rom f ormat table 7 describes the otp rom configuration fields and their default values. table 8 describes the pin configuration fields and their default values. table 7. otp rom format (512 bytes) field offset size default set commands note vid 0 2 0x10c4 set_usb_config (command id 0x61) (little-endian) pid 2 2 0x87a0 (little-endian) max power 4 1 0x32 50 x 2 ma = 100 ma power mode 5 1 0x00 usb bus-powered; voltage regulator enabled release version 6 2 0x0100 major release, minor release (big-endian) transfer priority 8 1 0x01 high-priority write manufacturing string 1 963 0x2a, 0x03, l?silicon laboratories? set_manufacturing_string1 (command id 0x63) 126-byte usb string descriptor (padded with 0x00) manufacturing string 2 72 63 set_manufacturing_string2 (command id 0x65) product string 1 135 63 0x32, 0x03, l?cp2130 usb- to-spi bridge? set_product_string1 (command id 0x67) 126-byte usb string descriptor (padded with 0x00) product string 2 198 63 set_product_string2 (command id 0x69) serial string 261 62 0x12, 0x03, set_serial_string (command id 0x6b) unique serial?32-bit hexadecimal serial number represented as 8, utf-16 upper- case letters/numerals. example: l?56789abc?. max 62-byte usb string descriptor. reserved 323 1 0xff ? pin config 324 20 see table 8 set_pin_config (command id 0x6d) customized fields 344 2 0xffff ? lock byte 346 2 0xffff set_lock_byte (command id 0x6f) reserved 348 164 0xff, ..., 0xff ?
AN792 74 rev. 0.3 table 8. pin config default values (20 bytes) field default function gpio.0 0x03 cs0 (push-pull output) gpio.1 0x03 cs1 (push-pull output) gpio.2 0x03 cs2 (push-pull output) gpio.3 0x04 rtr (input) gpio.4 0x04 evtcntr rising edge (input) gpio.5 0x04 clkout (push-pull output) gpio.6 0x00 gpio (input) gpio.7 0x02 gpio (push-pull output) gpio.8 0x04 spiact (push-pull output) gpio.9 0x04 suspend (push-pull output) gpio.10 0x04 suspend (push-pull output) suspend level 0x0000 suspend mode and levels are not used suspend mode 0x0000 wakeup mask 0x0000 no pins used for wakeup wakeup match 0x0000 divider 0x00 clkout = 93.75 khz
AN792 75 rev. 0.3 a ppendix b?p in c onfiguration o ptions some of the pins of the cp2130 are configurable as inputs, open-drain outputs, or push-pull outputs. these options are configured when the device has enumerated and is operating in a normal mode. when the cp2130 is in usb suspend, all of the configurable pins are limit ed to be open-drain or push-pull outputs. the following describes the differences between open- drain and push-pull, and the difference in behavior in suspend mode. see the cp2130 data sheet for the electrical specifications of the gpio pins. ? gpio input when a pin is configured as a gpio input, the pin ca n read a logic high or logic low value. internally, the gpio pin is connected to the vio pin through a resistor. if the pin is not connected exte rnally, it will return a logic high or 1. any voltages connected to the pin should conform to data sheet specifications. ? open-drain output when a pin is configured as a gpio open-drain output, the pin can output a logic high or logic low value. the default value is logic high, and a logic high value is created by internally connecting the gpio pin to the vio pin through a resistor. in this mode, the pin is unable to source much cu rrent when driving a logic high. if the set_gpio_mode_and_level (command id 0x23) or set_gpio_values (command id 0x21) command is used to change the output to a logic low, the pin is internally connected to gnd. ? push-pull output when a pin is configured as a gpio push-pull output, the pin can output a logic high or logic low value. when driving a logic high value, the pin is directly connected to the vio pin internally and can source current for devices, such as leds. wh en driving a logic low value, the pi n is internally connected to gnd. ? suspend mode when the device is in suspend mode , all of the gpio pins are forced to be open-drain or push-pull outputs. the mode of each gpio pin (open-drain or push-pull) and output value (logic-high or logic-low) is an otp rom configurable value which is set using the se t_pin_config (command id 0x6d) command. the modes and values of the pins during suspend can be th e same or different as when the device is in normal mode. to maintain the same electric al characteristics of a gpio input pin during suspend, configure the pin for open-drain mode with the output latch value set to logic-high or 1.
AN792 76 rev. 0.3 c ontact i nformation silicon laboratories inc. 400 west cesar chavez austin, tx 78701 tel: 1+(512) 416-8500 fax: 1+(512) 416-9669 toll free: 1+(877) 444-3032 please visit the silicon labs technical support web page: https://www.silabs.com/support/pages/contacttechnicalsupport.aspx and register to submit a technical support request. patent notice silicon labs invests in research and development to help our cust omers differentiate in the market with innovative low-power, s mall size, analog- intensive mixed-signal soluti ons. silicon labs' extensive patent portfolio is a testament to our unique approach and world-clas s engineering team. silicon laboratories and silicon labs are trademarks of silicon laboratories inc. other products or brandnames mentioned herein are trademarks or registered trademarks of their respective holders. the information in this document is believed to be accurate in all respects at the time of publ ication but is subject to change without notice. silicon laboratories assumes no responsibili ty for errors and omissions, and disclaim s responsibility for any consequences resu lting from the use of information included herein. a dditionally, silicon laboratorie s assumes no responsibility for the functioning of und escribed fea- tures or parameters. silicon laboratories reserves the right to make changes without further notice. silicon laboratories makes no warran- ty, representation or guarantee regarding t he suitability of its products for any par ticular purpose, nor does silicon laborato ries assume any liability arising out of the application or use of any product or circuit, and specif ically disclaims any and all liability, in cluding without limitation consequential or incidental damages . silicon laboratories products are not designed, intended, or authorized for use in applica tions intend- ed to support or sustain life, or for any other application in which the failure of the silicon laboratories product could crea te a situation where personal injury or death may occur. should buyer purchase or us e silicon laboratories products for any such unintended or unaut horized application, buyer shall indemnify and hold silicon laboratories harmle ss against all claims and damages.


▲Up To Search▲   

 
Price & Availability of AN792

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X